package com.example.cloud.apis;

import com.example.cloud.entities.PayDTO;
import com.example.cloud.resp.ResultData;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2024-03-09
 * Time: 13:28
 */

//@FeignClient(value = "cloud-payment-service") // 支付微服务的 Feign 接口，直接访问微服务，一般用于内部
@FeignClient(value = "cloud-gateway") // 支付微服务的 Feign 接口，通过 Gateway 网关，一般用于外部
public interface PayFeignApi {

    @PostMapping("/pay/add")
        // 通过这个直接调用到 http://cloud-payment-service/pay/add
    ResultData addPay(@RequestBody PayDTO payDTO);

    @GetMapping("/pay/get/{id}")
        // / 通过这个直接调用到 http://cloud-payment-service/pay/get/{id}
    ResultData getById(@PathVariable("id") int id);

    // 验证 Feign 天生就支持负载均衡
    @GetMapping("/pay/get/info")
    // / 通过这个直接调用到 http://cloud-payment-service/pay/get/info
    String getInfoByConsul();

    //=========Resilience4j CircuitBreaker 的例子
    @GetMapping(value = "/pay/circuit/{id}")
    public String myCircuit(@PathVariable("id") Integer id);


    /**
     * Resilience4j Bulkhead 的例子
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/pay/bulkhead/{id}")
    public String myBulkhead(@PathVariable("id") Integer id);

    /**
     * Resilience4j Ratelimit 的例子
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/pay/ratelimit/{id}")
    public String myRatelimit(@PathVariable("id") Integer id);


    /**
     * Micrometer(Sleuth)进行链路监控的例子
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/pay/micrometer/{id}")
    public String myMicrometer(@PathVariable("id") Integer id);


    /**
     * GateWay进行网关测试案例01
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/pay/gateway/get/{id}")
    public ResultData getById(@PathVariable("id") Integer id);

    /**
     * GateWay进行网关测试案例02
     *
     * @return
     */
    @GetMapping(value = "/pay/gateway/info")
    public ResultData<String> getGatewayInfo();
}
